package com.tuanzi.controller.mqtt;

import com.tuanzi.entity.MyMqttMessage;
import com.tuanzi.mqtt.MqttGateway;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author tuanzi
 * @version 1.0
 * @date 2022/4/24 11:36
 */

@RestController
public class MqttController {

    @Resource
    private MqttGateway mqttGateway;

    /**
     * 发送消息
     */
    @PostMapping("/send")
    public String send(@RequestBody MyMqttMessage myMessage) {
        // 发送消息到指定主题
        mqttGateway.sendToMqtt(myMessage.getTopic(), 1, myMessage.getContent());
        return "send topic: " + myMessage.getTopic()+ ", message : " + myMessage.getContent();
    }


}
